package leetcode_core.leetcode_2;

public class MyDequeue<V> {

    class ListNode <V>{
        V val;
        ListNode next;
        ListNode pre;
        ListNode() {}
        ListNode(V val) { this.val = val; }
        ListNode(V val, ListNode next) { this.val = val; this.next = next; }
    }

    public MyDequeue() {
        head = null;
        tail = null;
        size = 0;
    }
    private ListNode<V> head;
    private ListNode<V> tail;
    private int size;

    public void offerFirst(V val){
        ListNode<V> cur = new ListNode<>(val);
        if(head == null){
            head = cur;
            tail = cur;
        }else{
            cur.next = head;
            head.pre = cur;
            //cur.pre = null
            head = cur;
        }
        this.size++;
    }

    public void offerLast(V val){
        ListNode<V> cur = new ListNode<>(val);
        if(head == null){
            return;
        }else{
            cur.pre = tail;
            tail.next = cur;
            tail = cur;
        }
        this.size--;
    }

    public V getFirst(){
        return head.val;
    }

    public V getLast(){
        return tail.val;
    }





}
